<?php
namespace app\home\controller;

use think\Controller;
use think\Session;
use think\Request;
use app\home\model\CartsModel;

class Carts extends Common
{
	public function carts()
	{
		$CartsModel = new CartsModel();
		$list = $CartsModel->getUserCart();
		$this->assign('list',$list);
		return $this->fetch();
	}


	/**
	*	加入购物车-商品信息
	*/
	public function addCart()
	{
		$data = $this->request->param();
		$CartsModel = new CartsModel();
		$list = $CartsModel->addCart($data);
		if($list){
			return returnJson($code=0,$msg='添加成功',(int)$list);
		}else{
			return returnJson($code=1,$msg='添加失败',$list);
		}
	}

	/**
	*	加入购物车-商品规格数量
	*/

	public function addCartInfo()
	{
		$data = $this->request->param();
		$CartsModel = new CartsModel();
		$list = $CartsModel->addCartInfo($data);
		if($list){
			return returnJson($code=0,$msg='添加成功',$list);
		}else{
			return returnJson($code=1,$msg='添加失败',$list);
		}
	}

	/**
	*	购物车的总价格
	*/
	public function addCartsTotal()
	{
		$data = $this->request->param();
		$CartsModel = new CartsModel();
		$list = $CartsModel->addCartsTotal($data['tid']);
		if($list){
			return returnJson($code=0,$msg='添加成功',$list);
		}else{
			return returnJson($code=1,$msg='添加失败',$list);
		}
	}


	/**
	*	立即购买-商品信息
	*/
	public function addNows()
	{
		$data = $this->request->param();
		$CartsModel = new CartsModel();
		$list = $CartsModel->addNows($data);
		if($list){
			return returnJson($code=0,$msg='添加成功',(int)$list);
		}else{
			return returnJson($code=1,$msg='添加失败',$list);
		}
	}

	/**
	*	立即购买-商品规格数量
	*/

	public function addNowsInfo()
	{
		$data = $this->request->param();
		$CartsModel = new CartsModel();
		$list = $CartsModel->addNowsInfo($data);
		if($list){
			return returnJson($code=0,$msg='添加成功',$list);
		}else{
			return returnJson($code=1,$msg='添加失败',$list);
		}
	}

	/**
	*	立即购买的总价格
	*/
	public function addNowsTotal()
	{
		$data = $this->request->param();
		$CartsModel = new CartsModel();
		$list = $CartsModel->addNowsTotal($data['tid']);
		return returnJson($code=0,$msg='添加成功',$list);

	}

	/**
	*	单条购物车商品-商品信息
	*/
	public function getCartGoods()
	{
		$data = $this->request->param();
		$CartsModel = new CartsModel();
		$list = $CartsModel->getCartGoods($data['id']);
		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}

	/**
	*	ajax 添加购物车里某件商品的数量
	*/
	public function addCartInfoPost()
	{
		$data = $this->request->param();
		$CartsModel = new CartsModel();
		$list = $CartsModel->addCartInfoPost($data['id']);
		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}

	/**
	*	ajax 减少购物车里某件商品的数量
	*/
	public function deleteCartInfoPost()
	{
		$data = $this->request->param();
		$CartsModel = new CartsModel();
		$list = $CartsModel->deleteCartInfoPost($data['id'],$data['tid']);
		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}


	/**
	*	删除购物车
	*/
	public function deleteCart()
	{
		$data = $this->request->param();
		$CartsModel = new CartsModel();
		$list = $CartsModel->deleteCart($data['id']);
		if($list){
			return returnJson($code=0,$msg='获取成功',$list);
		}else{
			return returnJson($code=1,$msg='获取失败',$list);
		}
	}
}

